import React from 'react'

import {Switch,Route,Redirect} from 'react-router-dom'
import { RouterData} from './router.d'
interface Props{
    routes:RouterData[]
}

function RouterView({routes}:Props){
    let routeArr = routes.filter((item:RouterData) => item.component);
    let redirectArr = routes.filter((item:RouterData) => item.redirect);
    return <Switch>
        {/* /home  ===>Home */}
        {routeArr.length && routeArr.map((item:RouterData) => <Route key={item.path} path={item.path} render={(props) => {
            return <item.component {...props} routes={item.children}></item.component>
        }}></Route>)}
        {
            redirectArr.map((item:RouterData) => <Redirect key={item.path} from={item.path} to={item.redirect}></Redirect>)
        }
    </Switch>
}

export default RouterView